package com.petAdoption.manager.controller;


import com.petAdoption.manager.entity.Pet;
import com.petAdoption.manager.entity.Producttype;
import com.petAdoption.manager.service.IProducttypeService;
import com.petAdoption.manager.util.Result;
import com.petAdoption.manager.vo.PetVO;
import com.petAdoption.manager.vo.ProducttypeVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王倩茹
 * @since 2023-08-28
 */
@RestController
@RequestMapping("/producttype")
public class ProducttypeController {
    @Resource
    private IProducttypeService producttypeService;
    @Resource
    private Result result;

    @GetMapping("/findAll")
    public Result findAll(){
        List<ProducttypeVO> list = producttypeService.findAll();
        if(list!=null && !list.isEmpty()){
            return result.success("查找成功",list);
        }
        return result.fail("查找失败");
    }


    @GetMapping("/findByName")
    public List<ProducttypeVO> findByIdName(String producttypeName){
        List<ProducttypeVO> rows = producttypeService.findByName(producttypeName);
        return producttypeService.findByName(producttypeName);
    }


    @PutMapping("/updateProductType")
    public Result updateProductType(@RequestBody Producttype producttype) {
        int rows = producttypeService.updateProductType(producttype);
        if (rows > 0) {
            return result.success("修改成功", rows);
        } else {
            return result.fail("修改失败");
        }
    }


    @DeleteMapping("/delProductType")
    public Result delProductType(Integer producttypeId){
        int rows = producttypeService.delProductType(producttypeId);
        if(rows>0){
            return result.success("删除成功",rows);
        }else {
            return result.fail("删除失败");
        }
    }


    @PostMapping("/addProductType")
    public Result addProductType(@RequestBody Producttype producttype) {
        int rows = producttypeService.addProductType(producttype);
        if (rows > 0) {
            return result.success("添加成功", rows);
        } else {
            return result.fail("添加失败");
        }
    }







}
